Repository navigation
Interactivity: Return useMemo and useCallback hooks - #60474
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +122 B (0%) Total Size: 1.73 MB
ℹ️ View Unchanged
|
|
It looks like some simple unit tests would fit here perfectly so folks don’t always need to open the browser to validate it. |
| * function. | ||
| * @param {any[]} inputs If present, effect will only activate if the | ||
| * @param {Function} callback Callback function. | ||
| * @param {any[]} inputs If present, the callback will only be updated if the |
There was a problem hiding this comment.
JSDoc misses now the @return pragma for both updated functions.
I agree, but I don't think there's any set up for unit tests for interactivity. With these hooks that's something we'd have to figure out, it's usually not trivial to test hooks (at least with React). I could add another e2e test for hooks, there isn't one yet. |
|
Adding e2e test only to verify whether a function returns something is rather too much. It can be tested manually, too. |
Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
Return a value from the useMemo and useCallback hooks. --------- Co-authored-by: sirreal <jonsurrell@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org>
What?
Return a value from
useMemoanduseCallbackhooks.Observed while reviewing #60149.
Why?
The
useCallbackanduseMemohooks are intended to be analogous to preact hooks and should return a value.Testing Instructions
Run this with a plugin with a
viewScriptModulethat uses these hooks, like this:Render some HTML like this:
You should see this logged to the console:
{ "cb": ƒ, "cb_": "called back", "m": "memoized", "r": "ref" }